Conversation
|
I find the |
|
I've always found the f (fun x ->
e
)Note that there's a level of indentation coming from it just being in the function argument of f @@ fun x ->
ewhich tries to give the impression of linear code as opposed to going down into a scope (which it does). And that's exactly the kind of code let binding operators were introduced for and have it just as let@ x = f in
e(Here the This offers a very easy way to avoid file descriptor leaks. Instead of the buggy let f = open "foo.txt" in
ejust do let@ f = with_open "foo.txt" in
eNo need to touch/reindent People have complained about such operator elsewhere as well (ocaml/ocaml#9887), but not for this reason at all. There nobody is advocating for the middle |
I will have to look it up, when I encounter it, but this is more due to my Ocaml illiteracy - same is the case for lots of other operators that I do not encounter on a daily base. It it helps to contain the file handle leak in an elegant way, then why not. |
As we already have the |
|
I have no preference here, so I will just join the majority. |
I'll have to see about the semgrep false positives before we can really do this anyway. Having a semgrep rule to suggest |
|
Alright, if everyone else is on board, let's do it! |
This is on top of #1880.
Instead of writing
(which is a bit odd indentaiton-wise), this provides a neat way to write it more idiomatically as
This particularly makes sense for various
Fun.protectderivatives, like the file operations introduced in #1880 to not forget closing the file (even in the case of exceptions).Such an operator already exists, e.g. in the containers library.
TODO
letmatches custom binding operators (e.g.let@) in OCaml semgrep/semgrep#11432.